package com.pactera.demo.base.service.impl;

import com.pactera.demo.base.dto.RoleResource;
import com.pactera.demo.base.entity.Role;
import com.pactera.demo.base.mapper.RoleMapper;
import com.pactera.demo.base.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 角色定义表 服务实现类
 * </p>
 *
 * @author mybatis.plus
 * @since 2020-02-27
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    private RoleMapper roleMapper;
    @Override
    @Transactional
    public void bindResourcesToRole(List<RoleResource> roleResources) {
        roleResources.stream().forEach(x -> this.roleMapper.insertRoleResource(x));
    }

    @Override
    public Set<String> queryRolesByPattern(String pattern,String method) {
        Assert.notNull(method, "Request method must not be null!");
        return this.roleMapper.selectRoleCodesByPatten(pattern,method.toUpperCase());
    }

    public RoleServiceImpl(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }
}
